(function(){
	$(function(){
		var headerPic = (function(){
			var config = {
				$button:$('#import-img-button'),
				$picArea:$('#id-photo'),
				$uploader:$('#loader'),
				$viewImgTpl:$('.id-photo .show-photo'),
				$inputTpl:$("input[name='idnum_pic']"),
				imgType:'person'
			};
			var loader = BMXimg.init(config);
			loader.then(function(d,$e){
				if(d.state==200){
					//console.log($e);
					console.log(config.$viewImgTpl,d.data['url'])
					config.$viewImgTpl.attr('src', d.data['url']);
					config.$inputTpl.val(d.data.photoId);
				}else{
					alert('上传失败')
				}
			});
			return loader;
		})();
	})
})();

(function(){
	$(function(){
		var hint = $('.mistake-hint');
		var setPassButton = $('#modify-pass-button a')
        var setInfoButton = $('#modify-info-button a')
		hint.hide()
		setPassButton.click(function(e){
			e.preventDefault();
			if($('.input-pass').val() != $('.input-repass').val()){
				hint.show()
				return false;
			}else{
				$('#pass').submit();
			}
		})
        setInfoButton.click(function(e){
            $('#user-info').submit();
        })
	})
})()


$(function(){
    //百度地图API功能
    var map = new BMap.Map("allmap");
    map.addControl(new BMap.NavigationControl());
    map.enableScrollWheelZoom();    //启用滚轮放大缩小
    map.enableContinuousZoom();    //启用地图惯性拖拽
    //map.setZoom(10);
	api.solo( "siteInfo", [], function(d){
		var siteInfo= d.data;
		map.centerAndZoom(new BMap.Point(siteInfo.lon,siteInfo.lat),11);
	});
    map.centerAndZoom(new BMap.Point(117.565297,33.547786),13);

    // 读取服务站列表
    var $stationSelect=$("#default-station-name");
    var $stationSelectTpl=$stationSelect.find("option").remove();
    api.solo( "serviceList", [], function(d){
        for(var i in d.data.list){
            // 标注地图
            serviceInfo=d.data.list[i];
            var point = new BMap.Point(serviceInfo.longitude,serviceInfo.latitude);
            var marker = new BMap.Marker(point);  // 创建标注
            console.log(marker);
            map.addOverlay(marker);              // 将标注添加到地图中
            marker.serviceInfo=serviceInfo;
            marker.addEventListener("click", function(e){
                var p = e.target;
                console.log(p.serviceInfo);
                $stationSelect.val(p.serviceInfo.id);
            });

            // 增加显示
            var $tmp=$stationSelectTpl.clone();
            $tmp.data("serviceInfo",serviceInfo);
            console.log(serviceInfo);
            $tmp.attr("value",serviceInfo.id);
            $tmp.text(serviceInfo.service_name+" "+serviceInfo.address_string+(serviceInfo.address_text||"")+" ");
            $stationSelect.append($tmp);
            $stationSelect.find('option').show()
        }
        $stationSelect.val(_userInfo.service_id);
    });
});


